﻿#ifndef C_MY_SERVER_H
#define C_MY_SERVER_H

#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "sqlapi.lib")

#include "..\..\res\Server\resource.h"
#include "..\..\include\Server\CAsyncServer.h"
#include "..\..\include\common\MD5\md5.h"
#include "..\..\include\common\NET_CMD.h"
#include "..\..\include\common\sqlapi\SQLAPI.h"
#include "..\..\include\common\DealTime\DealTime.h"
#include <stdio.h>
#include <commctrl.h>
#include <string>
#include <time.h>
#include <regex>

using namespace std;

//////////////////////////////////////////////////////////////////////////
//宏定义


//时钟ID
#define IDT_CHECK_TIME	10001	//检测心跳包是否同步超时的时钟
#define IDT_DEAL_TIME	10002	//用于对客户端的心跳包时间进行倒计时

//时钟回调函数
extern VOID CALLBACK Heart_CheckProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime);
extern VOID CALLBACK Heart_DealTimeProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime);

class CMyServer
{
public:
	//绑定窗口句柄
	inline void SetWindowHandle(HWND hWnd)
	{
		this->m_hWnd = hWnd;
	}
	//初始化界面
	void InitUI();
	//开启服务
	BOOL StartServer();
	//停止服务
	void StopServer();
	//添加日志
	void AddLog(LPCTSTR format, ...);
	void AddLog(LPCSTR format, ...);
	//初始化公共控件
	BOOL InitCom();
	//清空日志列表
	void ClearLog();
	//生成客户端密钥（skey）
	void CreateSKey(char *lpUsername, SYSTEMTIME tm, char *lpSKey);
	//处理接收到的命令
	void DispatchCommand(SOCKET s, NET_CMD cmd);
	//更新在线列表
	void UpdateOnlineList();
	//转换SADateTime到CDealTime
	CDealTime SAToDeal(SADateTime &t) const;
	//转换CDealTime到SADateTime
	SADateTime DealToSA(CDealTime &t) const;
	//添加服务器日志
	void CMyServer::AddServerLog(char *lpText, char *lpUsername);

public:
	CAsyncServer server;	//服务端通信对象

private:
	HWND m_hWnd;
	CDebug debug;
	SAConnection m_DbConn;	//数据库连接对象
	//CIPLocator m_Locator;
};

#endif 